﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Mail;
using EventReminder.Common;

namespace EventReminder.Server
{
    public partial class frmMain : Form
    {
        GodObject _godObject;

        public frmMain()
        {
            InitializeComponent();
            _godObject = new GodObject();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            _godObject.Load();

            UpdateView();

            _godObject.OpenService();
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            _godObject.CloseService();
            this.Close();
            base.OnClosing(e);
            
        }

        public void UpdateView()
        {
            foreach (string s in _godObject.AllEvents)
            {
                lstAllEvents.Items.Add(s);
            }

            lblEventTotal.Text = _godObject.AllEvents.Count.ToString();
            foreach (string s in _godObject.Users)
            {
                lstUsers.Items.Add(s);
            }
            lblUserTotal.Text = _godObject.Users.Count.ToString();
        }

        private void cmdSend_Click(object sender, EventArgs e)
        {
            //SendEmailMessage();
            EventData ed = new EventData();
            ed.ID = 4;
            ed.Date = DateTime.Parse("4/28/2012 1:30:00 PM");
            ed.Title = "Message Add";
            ed.Description = "Test to add data to system";
            string[] emails = {"lqube2000@gmail.com"};
            ed.Emails = emails;
            ed.Reminder = "1";
            ed.Type = EventTypes.Meeting;
            ed.FollowUp = false;
            ed.LastReminderSent = DateTime.Now;
            ed.NextReminderDue = DateTime.Now;
            ed.MessageOwner = 2;

 
            _godObject.AddEvent(ed);
        }

        private void cmdChange_Click(object sender, EventArgs e)
        {
            EventData ed = new EventData();
            ed.ID = 3;
            ed.Date = DateTime.Parse("4/28/2012 1:30:00 PM");
            ed.Title = "Message Add";
            ed.Description = "Test to add data to system";
            string[] emails = { "lqube2000@gmail.com" };
            ed.Emails = emails;
            ed.Reminder = "1";
            ed.Type = EventTypes.Meeting;
            ed.FollowUp = false;
            ed.LastReminderSent = DateTime.Now;
            ed.NextReminderDue = DateTime.Now;
            ed.MessageOwner = 2;

            EventData ednew = new EventData();
            ednew.ID = 3;
            ednew.Date = DateTime.Parse("4/28/2012 4:30:00 PM");
            ednew.Title = "Message Modified";
            ednew.Description = "Test to change data to system";
            //emails = { "lqube2000@gmail.com" };
            ednew.Emails = emails;
            ednew.Reminder = "1";
            ednew.Type = EventTypes.Meeting;
            ednew.FollowUp = false;
            ednew.LastReminderSent = DateTime.Now;
            ednew.NextReminderDue = DateTime.Now;
            ednew.MessageOwner = 2;

            _godObject.ModifyEvent(ed, ednew);
        }

        private void cmdDelete_Click(object sender, EventArgs e)
        {
            EventData ed = new EventData();
            ed.ID = 4;
            ed.Date = DateTime.Parse("4/28/2012 1:30:00 PM");
            ed.Title = "Message Add";
            ed.Description = "Test to add data to system";
            string[] emails = { "lqube2000@gmail.com" };
            ed.Emails = emails;
            ed.Reminder = "1";
            ed.Type = EventTypes.Meeting;
            ed.FollowUp = false;
            ed.LastReminderSent = DateTime.Now;
            ed.NextReminderDue = DateTime.Now;
            ed.MessageOwner = 2;

            _godObject.DeleteEvent(ed);
        }
    }
}
